package com.woniuxy.service.impl;


import com.woniuxy.dao.PropertyMapper;
import com.woniuxy.dao.ServerOrdersMapper;
import com.woniuxy.dao.VendorMapper;
import com.woniuxy.dto.MiddleData;
import com.woniuxy.dto.ResultAllService;
import com.woniuxy.dto.ResultFinishedSercer;
import com.woniuxy.dto.ResultHasServer;
import com.woniuxy.pojo.Property;
import com.woniuxy.pojo.ServerOrders;
import com.woniuxy.service.ProServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class ProServerServiceImpl implements ProServerService {

    @Autowired
    private PropertyMapper propertyMapper;

    @Autowired
    private ServerOrdersMapper serverOrdersMapper;
    //查询所有用户向物业的预约服务
    @Override
    public List<ResultAllService> findAllService(Long vid,String name,Integer currentPage,Integer pageSize) {
        return propertyMapper.findAllServiceByVid(vid,name,currentPage,pageSize);
    }


    //物业接取用户服务
    @Override
    public void receiveServer(Long ssid) {
        //服务接取后改变预约表中的状态码，(类似软删除，接取后不在展示给物业)
        propertyMapper.updateSubscribeStatus(ssid);
        //MiddleData查询需要的数据
        MiddleData m = propertyMapper.findMiddleData(ssid);
        ServerOrders so = new ServerOrders();
        so.setSerId(m.getSsid());//预约表主键
        so.setUserId(m.getUserId());//用户id
        so.setPayStatus(0);
        so.setPrice(m.getPrice());//服务价格
        so.setCreateTime(new Date());
        so.setStatus(1);
        so.setOrderNum(UUID.randomUUID().toString().replaceAll("-",""));//生成订单号
        //服务接取后，生成服务订单信息
        serverOrdersMapper.insert(so);
    }


    //查询物业已接取的服务
    @Override
    public List<ResultHasServer> findHasServerByPropertyId(Long pid) {
        return propertyMapper.findHasServerByPropertyId(pid);
    }


    //查询物业已完成的服务
    @Override
    public List<ResultFinishedSercer> findFinishServerOrder(Long pid) {
        return propertyMapper.findFinishServerOrder(pid);
    }
}
